//
//  SEDoctorViewModel.swift
//  SmartEyeForPatient
//
//  Created by QDSG on 2021/4/21.
//

import UIKit

final class SEDoctorViewModel: SEBaseViewModel {
    var doctorList: [SEDoctorDetail] = []

    var doctorName: String = ""
    var hospitalId: String = ""
    var departmentId: String = ""
    var provinceId: String = ""
    var cityId: String = ""
    var areaId: String = ""

    var examineRecordVm = SEExamineRecordViewModel()

    var patientInfo = SEPatientDetailViewModel()
    
    var numberOfSections: Int { doctorList.count }
    
    func viewModel(at indexPath: IndexPath) -> SEDoctorDetailViewModel {
        return SEDoctorDetailViewModel(model: doctorList[indexPath.section])
    }
    
    /// 获取线上问诊医生列表
    func getDoctorListOfOnlineInquiry(loadMore: Bool) {
        page = loadMore ? page + 1 : 1
        SEHttpManager.shared.request(SEDoctorAPI.doctorListOfOnlineInquiry(doctorName: doctorName, hospitalId: hospitalId, departmentId: departmentId, provinceId: provinceId, cityId: cityId, areaId: areaId, page: page), model: SEDoctorModel.self) { (model, httpStatus) in
            switch httpStatus {
            case .success:
                if !loadMore {
                    self.doctorList = model?.list ?? []
                } else {
                    self.doctorList.append(contentsOf: model?.list ?? [])
                }
                self.hasMore = model?.totalPage ?? 0 > self.page
            default: break
            }
            self.updateData?(httpStatus)
        }
    }
    
}
